package com.mkono.infra.untils;

import android.graphics.Bitmap;

import java.io.ByteArrayOutputStream;

/**
 * Created by huang on 2019/12/20.
 */

public class Util {

    public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();//初始化一个流对象
        bmp.compress(Bitmap.CompressFormat.PNG, 100, output);//把bitmap100%高质量压缩 到 output对象里

        bmp.recycle();//自由选择是否进行回收


        byte[] result = output.toByteArray();//转换成功了
        try {
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
